<template>
  <div>
    {{ $store.state.username }}
    <van-button type="primary" @click="exit">退出登录</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  methods: {
    exit() {
      this.$store.commit("exit");
      this.$router.push("/login");
    },
  },
  created() {},
  mounted() {},
  components: {},
  computed: {},
  watch: {},
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      //vm相当于是this
      if (vm.$store.state.username) {
        next();
      } else {
        next("/login");
      }
      //判断vuex里有没有 存的有用户名
    });
  },
  //组件级守卫 守卫当前页面
};
</script>

<style lang="scss" scoped></style>
